package so.sao.code.service.web.api;

import java.util.Date;
import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import so.sao.code.dto.request.ThirdPartyCodeFileHandleRequest;
import so.sao.code.dto.response.ThirdPartyCodeFileHandleDto;
import so.sao.code.service.service.ThirdPartyCodeFileRecordService;

@Api(tags = "thirdPartyCodeFileHandle", value = "第三方码文件操作记录控制器")
@RestController
@RequestMapping("/api/thirdPartyCodeFileHandle")
public class ThirdPartyCodeFileHandleApiController {
	
	@Autowired
	ThirdPartyCodeFileRecordService thirdPartyCodeFileHandleService;
	
	@ApiOperation(value = "根据企业Id和文件名获取文件处理信息", notes = "根据企业Id和文件名获取文件处理信息")
	@GetMapping(value = "/get/{eseId}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<ThirdPartyCodeFileHandleDto> get(@PathVariable("eseId") Long eseId,
			String fileName){
		return new ResponseEntity<>(thirdPartyCodeFileHandleService.findByEseIdAndFileName(eseId, fileName), HttpStatus.FOUND);
	}
	
	@ApiOperation(value = "更新第三方文件处理信息", notes = "更新第三方文件处理信息")
	@GetMapping(value = "/modify",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<ThirdPartyCodeFileHandleDto> modify(@Valid ThirdPartyCodeFileHandleRequest codeFileHandleRequest){
		return new ResponseEntity<>(thirdPartyCodeFileHandleService.modify(codeFileHandleRequest), HttpStatus.FOUND);
	}
	
	@ApiOperation(value = "根据第三方码查询top码", notes = "根据第三方码查询top码")
	@GetMapping(value = "/findTopCode",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<String> findTopCode(Long thirdPartyCode,String domain,String subDomain,Long eseId){
		return new ResponseEntity<>(thirdPartyCodeFileHandleService.findTopCode(thirdPartyCode,domain,subDomain,eseId), HttpStatus.FOUND);
	}
	
	@ApiOperation(value = "查询文件处理信息", notes = "查询文件处理信息")
	@GetMapping(value = "/find",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<List<ThirdPartyCodeFileHandleDto>> find(Long eseId,Date createDate){
		return new ResponseEntity<>(thirdPartyCodeFileHandleService.find(eseId,createDate), HttpStatus.FOUND);
	}
}
